<%-- 
    Document   : SanPham
    Created on : Oct 5, 2011, 5:51:14 PM
    Author     : kijoo
--%>


<%@page import="MODEL.POJO.*"%>
<%@page import="java.util.ArrayList"%>
<%@page import="MODEL.DAO.LoaiSanPhamDAO"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<%
    LoaiDanhMucPOJO loaidm = (LoaiDanhMucPOJO) request.getAttribute("LoaiDM");
    DanhMucPOJO danhm = (DanhMucPOJO) request.getAttribute("DM");
    SanPhamPOJO sanp = (SanPhamPOJO) request.getAttribute("TenSanPham");
    String loaisanpham = (String) request.getAttribute("LoaiSanPhams");
    int soluongtrang = (Integer) request.getAttribute("SoTrang");
    int xuly = (Integer) request.getAttribute("XyLy");
    String yeucau = "";
    if(request.getAttribute("YeuCau")!=null){
    yeucau = (String) request.getAttribute("YeuCau");
       }
%>

<div class="noidungldm">
    <%  if (xuly == 1) {
    %>
    <div class="sitemap"><a href="HomeController?Action=<%=loaisanpham%>&idloaisanpham=<%=loaisanpham%>">Trang Chủ</a> > <a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaisanpham=<%=loaisanpham%>&Trang=1">Sản Phẩm</a> > <a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaidanhmuc=<%=loaidm.getIdloaidanhmuc()%>&Trang=1"/><%=loaidm.getTenloaidanhmuc()%> </div>
    <%
        ArrayList<DanhMucPOJO> dsdm = (ArrayList<DanhMucPOJO>) request.getAttribute("DanhSachDMs");
        DanhMucPOJO dm;
        for (int i = 0; i < dsdm.size(); i++) {
            dm = dsdm.get(i);
    %>
    <div class="a"><a href="DanhSachSanPhamController?Action=<%= loaisanpham%>&iddanhmuc=<%= dm.getIddanhmuc()%>&Trang=1" >+<%=dm.getTendanhmuc()%></a></div>
    <%  }%>
    <div class="tieude"><%=loaidm.getTenloaidanhmuc()%><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaidanhmuc=<%=loaidm.getIdloaidanhmuc()%>&Trang=1&YeuCau=Tang"/>[Giá tăng dần]</a><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaidanhmuc=<%=loaidm.getIdloaidanhmuc()%>&Trang=1&YeuCau=Giam"/>[Giá Giảm Dần]</a><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaidanhmuc=<%=loaidm.getIdloaidanhmuc()%>&Trang=1&YeuCau=Moi"/>[Mới nhất]</a><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaidanhmuc=<%=loaidm.getIdloaidanhmuc()%>&Trang=1&YeuCau=XemNhieu"/>[Xem nhiều nhất]</a></div>
    <%} else if (xuly == 2) {
        ArrayList<SanPhamPOJO> dsdm = (ArrayList<SanPhamPOJO>) request.getAttribute("DanhSachDMs");
    %>
    <div class="sitemap"><a href="HomeController?Action=<%=loaisanpham%>&idloaisanpham=<%=loaisanpham%>">Trang Chủ</a> > <a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaisanpham=<%=loaisanpham%>&Trang=1">Sản Phẩm ><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaidanhmuc=<%=loaidm.getIdloaidanhmuc()%>&Trang=1"/><%=loaidm.getTenloaidanhmuc()%> </a> > <a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&iddanhmuc=<%=danhm.getIddanhmuc()%>&Trang=1"><%=danhm.getTendanhmuc()%> </a></div>
    <%
        SanPhamPOJO dm;
        if (dsdm.size() > 0) {
            for (int i = 0; i < dsdm.size(); i++) {
                dm = dsdm.get(i);
    %>
    <div class="a"><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idsanpham=<%=dm.getIdsanpham()%>&Trang=1" ><% if (dm.getDongsanpham() != null) {%>+<%=dm.getDongsanpham()%><%}%></a>
    </div>
    <%    }
        }%>
    <div class="tieude"><%=danhm.getTendanhmuc()%><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&iddanhmuc=<%=danhm.getIddanhmuc()%>&Trang=1&YeuCau=Tang"/>[Giá tăng dần]</a><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&iddanhmuc=<%=danhm.getIddanhmuc()%>&Trang=1&YeuCau=Giam"/>[Giá Giảm Dần]</a><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&iddanhmuc=<%=danhm.getIddanhmuc()%>&Trang=1&YeuCau=Moi"/>[Mới nhất]</a><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&iddanhmuc=<%=danhm.getIddanhmuc()%>&Trang=1&YeuCau=XemNhieu"/>[Xem nhiều nhất]</a></div>
    <%} else if (xuly == 3) {%>
    <div class="sitemap"><a href="HomeController?Action=<%=loaisanpham%>&idloaisanpham=<%=loaisanpham%>">Trang Chủ</a> > <a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaisanpham=<%=loaisanpham%>&Trang=1">Sản Phẩm ><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaidanhmuc=<%=loaidm.getIdloaidanhmuc()%>&Trang=1"/><%=loaidm.getTenloaidanhmuc()%> </a> > <a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&iddanhmuc=<%=danhm.getIddanhmuc()%>&Trang=1"><%=danhm.getTendanhmuc()%> </a><% if (sanp.getDongsanpham() != null) {%> > <a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idsanpham=<%=sanp.getIdsanpham()%>&Trang=1"><%=sanp.getDongsanpham()%> <%}%> </a> </div>
    <div class="tieude"><%if (sanp.getDongsanpham() != null) {%><%=sanp.getDongsanpham()%><%} else {%><%=danhm.getTendanhmuc()%><%}%><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idsanpham=<%=sanp.getIdsanpham()%>&Trang=1&YeuCau=Tang"/>[Giá tăng dần]</a><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idsanpham=<%=sanp.getIdsanpham()%>&Trang=1&YeuCau=Giam"/>[Giá Giảm Dần]</a><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idsanpham=<%=sanp.getIdsanpham()%>&Trang=1&YeuCau=Moi"/>[Mới nhất]</a><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idsanpham=<%=sanp.getIdsanpham()%>&Trang=1&YeuCau=XemNhieu"/>[Xem nhiều nhất]</a></div>
    <%--Hien Thi Loc San Pham--%>
    <%} else if (xuly == 4) {%>
    <div class="sitemap"><a href="HomeController?Action=<%=loaisanpham%>&idloaisanpham=<%=loaisanpham%>">Trang Chủ</a> > <a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaisanpham=<%=loaisanpham%>&Trang=1">Sản Phẩm ><a href="#"/><%=(String) request.getAttribute("Text")%></a></div>
    <div class="tieude"><%=(String) request.getAttribute("Text")%><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&giatu=<%=(String) request.getAttribute("giatu")%>&giaden=<%=(String) request.getAttribute("giaden")%>&Text=<%=(String) request.getAttribute("Text")%>&Trang=1&YeuCau=Tang"/>[Giá tăng dần]</a><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&giatu=<%=(String) request.getAttribute("giatu")%>&giaden=<%=(String) request.getAttribute("giaden")%>&Text=<%=(String) request.getAttribute("Text")%>&Trang=1&YeuCau=Giam"/>[Giá Giảm Dần]</a><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&giatu=<%=(String) request.getAttribute("giatu")%>&giaden=<%=(String) request.getAttribute("giaden")%>&Text=<%=(String) request.getAttribute("Text")%>&Trang=1&YeuCau=Moi"/>[Mới nhất]</a><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&giatu=<%=(String) request.getAttribute("giatu")%>&giaden=<%=(String) request.getAttribute("giaden")%>&Text=<%=(String) request.getAttribute("Text")%>&Trang=1&YeuCau=XemNhieu"/>[Xem nhiều nhất]</a></div>
    <% } else if (xuly == 5) {%>
    <div class="sitemap"><a href="HomeController?Action=<%=loaisanpham%>&idloaisanpham=<%=loaisanpham%>">Trang Chủ</a> > <a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaisanpham=<%=loaisanpham%>&Trang=1">Sản Phẩm</a> </div>
    <%
        ArrayList<LoaiDanhMucPOJO> ds = (ArrayList<LoaiDanhMucPOJO>) request.getAttribute("LoaiDanhMucs");
        for (int i = 0; i < ds.size(); i++) {
            LoaiDanhMucPOJO ldm = ds.get(i);
    %>
    <div class="a"><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaidanhmuc=<%=ldm.getIdloaidanhmuc()%>&Trang=1" >+<%=ldm.getTenloaidanhmuc()%></a></div>
    <%  }%>
    <div class="tieude"><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaisanpham=<%=loaisanpham%>&Trang=1&YeuCau=Tang"/>[Giá tăng dần]</a><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaisanpham=<%=loaisanpham%>&Trang=1&YeuCau=Giam"/>[Giá Giảm Dần]</a><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaisanpham=<%=loaisanpham%>&Trang=1&YeuCau=Moi"/>[Mới nhất]</a><a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaisanpham=<%=loaisanpham%>&Trang=1&YeuCau=XemNhieu"/>[Xem nhiều nhất]</a></div>
    <% }%> 
</div>

<div class="noidung">
    <%
        ArrayList<ChiTietSanPhamPOJO> dsctsp = (ArrayList<ChiTietSanPhamPOJO>) request.getAttribute("DanhSachCTSPs");
        for (int j = 0; j < dsctsp.size(); j++) {
            ChiTietSanPhamPOJO ctsp = dsctsp.get(j);
    %>
    <div>
        <table width="100%" border="0" align="center">
            <tr>
                <td width="19%">&nbsp;</td>
                <td width="61%"><a href="ChiTietController?Action=<%=loaisanpham%>&idchitietsanpham=<%=ctsp.getIdchitietsanpham()%>" title="<%=ctsp.getTensanpham()%>" style="color:#FF0000; font-size:16px;"><strong><span style="color:#0066FF; CURSOR: hand" onMouseOver="this.style.color='#FF0000'; " onMouseOut="this.style.color='#0066FF'; " ><%=ctsp.getTensanpham()%></span></strong></a></td>
                <td width="20%">&nbsp;</td>
            </tr>
            <tr>
                <td rowspan="3"><div align="center"><a href="ChiTietController?Action=<%=loaisanpham%>&idchitietsanpham=<%=ctsp.getIdchitietsanpham()%>"><img src="<%=ctsp.getHinh()%>" width="100px" height="100px"/></a></div></td>
                <td><strong>Model: </strong><%= ctsp.getIdsanpham()%></td>
                <td><div align="center" style="color:#FF0000"><%=ctsp.getGiaban()%> VNĐ</div></td>
            </tr>
            <tr>
                <td><strong>Thông tin: </strong><%=ctsp.getMota()%></td>
                <td><div align="center"><a href="CartController?Action=ChoVaoGioHang&idloaisanpham=<%=loaisanpham%>&idchitietsanpham=<%=ctsp.getIdchitietsanpham()%>"><img src="images/dathang1.gif"/></a></div></td>
            </tr>
            <tr>
                <td><strong>Bảo hành</strong> <%=ctsp.getBaohanh()%> Tháng | <strong>Kho hàng </strong><%=ctsp.getSoluongton()%></td>
                <td><div align="center"><a href="ChiTietController?Action=<%=loaisanpham%>&idchitietsanpham=<%=ctsp.getIdchitietsanpham()%>">[ Xem thêm ]</a></div></td>
            </tr>
            <tr>
                <td><div align="center">Lượt xem: <%= ctsp.getSolanxem()%> </div></td>

                <td>&nbsp;</td>


        </table>
        <hr>
    </div>
    <% }%>
</div>
<%-- phan trang --%>
<%if(soluongtrang>1){%>
<div class="phantrang">
    <%  int trangtruoc = 1;
        if (request.getParameter("Trang") != null) {
            int tranghienhanh = Integer.parseInt(request.getParameter("Trang"));
            if (tranghienhanh > 1) {
                trangtruoc = tranghienhanh - 1;
            }
        }
    %>
    <%-- xu ly hien thi phan trang voi link --%>
    <%
        if (xuly == 1) {
    %>
    <a  href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaidanhmuc=<%=loaidm.getIdloaidanhmuc()%>&Trang=<%=trangtruoc%>&YeuCau=<%=yeucau%>">[Trang trước]</a>Trang: 
    <%
            for (int i = 1; i <= soluongtrang; i++) {%>
    <a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaidanhmuc=<%=loaidm.getIdloaidanhmuc()%>&Trang=<%=i%>&YeuCau=<%=yeucau%>"><%=i%><a/>
        <% }%>
        <%  int trangsau = trangtruoc + 1;
            if (request.getParameter("Trang") != null) {
                int tranghienhanh = Integer.parseInt(request.getParameter("Trang"));
                if (trangsau < soluongtrang) {
                    trangsau = tranghienhanh + 1;
                }
            }%>
        <a  href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaidanhmuc=<%=loaidm.getIdloaidanhmuc()%>&Trang=<%=trangsau%>&YeuCau=<%=yeucau%>">[Trang sau]</a>
        <%} else if (xuly == 2) {%>
        <a  href="DanhSachSanPhamController?Action=<%=loaisanpham%>&iddanhmuc=<%=danhm.getIddanhmuc()%>&Trang=<%=trangtruoc%>&YeuCau=<%=yeucau%>">[Trang trước]</a>Trang: 
        <%  for (int i = 1; i <= soluongtrang; i++) {%>
        <a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&iddanhmuc=<%=danhm.getIddanhmuc()%>&Trang=<%=i%>&YeuCau=<%=yeucau%>"><%=i%><a/>
            <% }
                int trangsau = trangtruoc + 1;
                if (request.getParameter("Trang") != null) {
                    int tranghienhanh = Integer.parseInt(request.getParameter("Trang"));
                    if (trangsau < soluongtrang) {
                        trangsau = tranghienhanh + 1;
                    }
                }%>
            <a  href="DanhSachSanPhamController?Action=<%=loaisanpham%>&iddanhmuc=<%=danhm.getIddanhmuc()%>&Trang=<%=trangsau%>&YeuCau=<%=yeucau%>">[Trang sau]</a>
            <% } else if (xuly == 3) {%>
            <a  href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idsanpham=<%=sanp.getIdsanpham()%>&Trang=<%=trangtruoc%>&YeuCau=<%=yeucau%>">[Trang trước]</a>Trang: 
            <%  for (int i = 1; i <= soluongtrang; i++) {%>
            <a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idsanpham=<%=sanp.getIdsanpham()%>&Trang=<%=i%>&YeuCau=<%=yeucau%>"><%=i%><a/>
                <% }
                    int trangsau = trangtruoc + 1;
                    if (request.getParameter("Trang") != null) {
                        int tranghienhanh = Integer.parseInt(request.getParameter("Trang"));
                        if (trangsau < soluongtrang) {
                            trangsau = tranghienhanh + 1;
                        }
                    }%>
                <a  href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idsanpham=<%=sanp.getIdsanpham()%>&Trang=<%=trangsau%>&YeuCau=<%=yeucau%>">[Trang sau]</a>
                <% } else if (xuly == 4) {%>
                <a  href="DanhSachSanPhamController?Action=<%=loaisanpham%>&giatu=<%=(String) request.getAttribute("giatu")%>&giaden=<%=(String) request.getAttribute("giaden")%>&Text=<%=(String) request.getAttribute("Text")%>&Trang=<%=trangtruoc%>&YeuCau=<%=yeucau%>">[Trang trước]</a>Trang: 
                <%  for (int i = 1; i <= soluongtrang; i++) {%>
                <a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&giatu=<%=(String) request.getAttribute("giatu")%>&giaden=<%=(String) request.getAttribute("giaden")%>&Text=<%=(String) request.getAttribute("Text")%>&Trang=<%=i%>&YeuCau=<%=yeucau%>"><%=i%><a/>
                    <% }
                        int trangsau = trangtruoc + 1;
                        if (request.getParameter("Trang") != null) {
                            int tranghienhanh = Integer.parseInt(request.getParameter("Trang"));
                            if (trangsau < soluongtrang) {
                                trangsau = tranghienhanh + 1;
                            }
                        }%>
                    <a  href="DanhSachSanPhamController?Action=<%=loaisanpham%>&giatu=<%=(String) request.getAttribute("giatu")%>&giaden=<%=(String) request.getAttribute("giaden")%>&Text=<%=(String) request.getAttribute("Text")%>&Trang=<%=trangsau%>&YeuCau=<%=yeucau%>">[Trang sau]</a>
                    <% } else if (xuly == 5) {%>
                    <a  href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaisanpham=<%=loaisanpham%>&Trang=<%=trangtruoc%>&YeuCau=<%=yeucau%>">[Trang trước]</a>Trang: 
                    <%  for (int i = 1; i <= soluongtrang; i++) {%>
                    <a href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaisanpham=<%=loaisanpham%>&Trang=<%=i%>&YeuCau=<%=yeucau%>"><%=i%><a/>
                        <% }
                            int trangsau = trangtruoc + 1;
                            if (request.getParameter("Trang") != null) {
                                int tranghienhanh = Integer.parseInt(request.getParameter("Trang"));
                                if (trangsau < soluongtrang) {
                                    trangsau = tranghienhanh + 1;
                                }
                            }%>
                        <a  href="DanhSachSanPhamController?Action=<%=loaisanpham%>&idloaisanpham=<%=loaisanpham%>&Trang=<%=trangsau%>&YeuCau=<%=yeucau%>">[Trang sau]</a>
                        <% }%>
                        </div>
<% } %>